package com.zhsm.fuxi.mvp.presenter

import com.hankkin.library.mvp.presenter.RxLifePresenter
import com.hankkin.reading.control.UserControl
import com.hankkin.reading.http.HttpClientUtils
import com.zhsm.fuxi.mvp.contract.AttMenuContract
import com.zhsm.paipaiout.baselibrary.utils.LoadingUtils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

/**
 * Created by GuZhC on 2018/11/5.
 * describe:
 */
class AttMenuPresenter : RxLifePresenter<AttMenuContract.IView>(), AttMenuContract.IPresenter {
    override fun getZhimaAuthPath() {
        HttpClientUtils.Builder.getPaipiaHttp().getZhimaAuthPath(UserControl.getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().zfbPay(it)
                }, {
                    LoadingUtils.hideLoading()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }

    override fun zfbPay() {
        HttpClientUtils.Builder.getPaipiaHttp().zfbCashPledgePay(UserControl.getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().zfbPay(it)
                }, {
                    LoadingUtils.hideLoading()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }
    override fun updaateUserIn() {
        HttpClientUtils.Builder.getPaipiaHttp().updateUserInfo(UserControl.getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().updaateUserInfoSuccess(it)
                }, {
                    getMvpView().hideLoding()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }
    override fun freezeQuery(orderId: String) {
        getMvpView().showLoding()
        HttpClientUtils.Builder.getPaipiaHttp().freezeQuery(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().paySuccess(it)
                }, {
                    getMvpView().hideLoding()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }
    override fun alipayQuery(orderId: String) {
        getMvpView().showLoding()
        HttpClientUtils.Builder.getPaipiaHttp().alipayQuery(orderId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeEx({
                    getMvpView().paySuccess(it)
                }, {
                    getMvpView().hideLoding()
                }).bindRxLifeEx(RxLife.ON_DESTROY)
    }
}